#pragma once
#include "../game/FigureObject.h"
#include "../game/FightManager.h"
#include "../game/Resource.h"
#include "../stdafx.h"
namespace SLG
{
	extern LPDIRECT3DDEVICE9 g_pd3dDevice;

	struct Cell
	{
		Cell()
		{
			fid=-1;
		}

		D3DXVECTOR3 midPos;
		D3DXVECTOR3 minPos;
		D3DXVECTOR3 maxPos;
		int32 fid;
	};

	class Resource;
	class FigureObject;
	class FightManager;
	class World
	{
	public:
		World(void);
		~World(void);

		int32 m_curCell;
		int32 m_wWidth;
		int32 m_wHeight;
		float m_sWidth;
		float m_sHeight;
		LPDIRECT3DTEXTURE9 m_tex;
		LPDIRECT3DTEXTURE9 m_curTex;
		LPDIRECT3DINDEXBUFFER9 m_id;
		LPDIRECT3DVERTEXBUFFER9 m_vb;
		LPDIRECT3DVERTEXBUFFER9 m_curVb;
		bool LoadGround(int32,int32,const char*);
		HRESULT CreateGround();
		bool InitWorld(Resource*);
		bool AddFigureInCell(int32,int32,int32);
		FigureObject* m_Figure;
		FightManager* m_fManager;
		Cell* m_cell;
		int32 GetCurCellFid();
		D3DXVECTOR3 GetCellPos(int32,int32);
		D3DXVECTOR3 GetCellPos();
		HRESULT UpdateCursorCell(D3DXVECTOR3*);
		void DrawGround();
		void Draw(DWORD);
		void InitCell();
		bool CheckCell(int32,int32);
		bool GetCellIndex(D3DXVECTOR3 pos,int32* x,int32* y);
		
	};
}
